package com.animations;

import com.beans.BeginBean;
import com.beans.ButtonEvent;
import creator.ui.controller.VoicePlayer;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

public class BeginAction extends Animation {

  private BeginBean begin;

  public void loadBean() {
    this.begin = new BeginBean();
    getBeans().add(this.begin);
  }

  public void paint(Graphics g) {
    g.drawImage(
      this.begin.getBegin(),
      BeginBean.getBeginX(),
      BeginBean.getBeginY(),
      getMagicanvas()
    );
  }

  public void run() {
    getMagicanvas().repaint();
    LoadMouseListener(getMagicanvas());
  }

  private void LoadMouseListener(Magicanvas magicanvas) {
    magicanvas.addMouseListener(
      new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
          if (
            (e.getX() > BeginBean.getBeginX()) &&
            (
              e.getX() <
              BeginBean.getBeginX() +
              BeginAction.this.begin.getBeginW()
            ) &&
            (e.getY() > BeginBean.getBeginY()) &&
            (e.getY() < BeginBean.getBeginY() + BeginBean.getBeginH())
          ) BeginBean.setBeginY(BeginBean.getBeginOldY() + 3);
        }

        public void mouseReleased(MouseEvent e) {
          if (
            (e.getX() > BeginBean.getBeginX()) &&
            (
              e.getX() <
              BeginBean.getBeginX() +
              BeginAction.this.begin.getBeginW()
            ) &&
            (e.getY() > BeginBean.getBeginY()) &&
            (e.getY() < BeginBean.getBeginY() + BeginBean.getBeginH())
          ) {
            BeginBean.setBeginY(BeginBean.getBeginOldY());
            VoicePlayer.play("/res/sounds/sfx_swooshing.wav");
            new ButtonEvent().event("Begin");
          }
        }
      }
    );
  }
}
